<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BasePatientDetails {

	protected $m_bigintId;
	protected $m_intPatientId;
	protected $m_intMonthlyIncome;
	protected $m_strRelievedDate;
	protected $m_strDischargeDate;
	protected $m_strAdmissionDate;
	protected $m_intWardId;
	protected $m_intBeedNumber;
	protected $m_intCasePaperCount;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_bigintId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getMonthlyIncome(){
		return $this->m_intMonthlyIncome;
	}

	public function getRelievedDate(){
		return $this->m_strRelievedDate;
	}

	public function getDischargeDate(){
		return $this->m_strDischargeDate;
	}

	public function getAdmissionDate(){
		return $this->m_strAdmissionDate;
	}

	public function getWardId(){
		return $this->m_intWardId;
	}

	public function getBeedNumber(){
		return $this->m_intBeedNumber;
	}

	public function getCasePaperCount(){
		return $this->m_intCasePaperCount;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_bigintId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setMonthlyIncome( $MonthlyIncome ){
		$this->m_intMonthlyIncome = $MonthlyIncome;
	}

	public function setRelievedDate( $RelievedDate ){
		$this->m_strRelievedDate = $RelievedDate;
	}

	public function setDischargeDate( $DischargeDate ){
		$this->m_strDischargeDate = $DischargeDate;
	}

	public function setAdmissionDate( $AdmissionDate ){
		$this->m_strAdmissionDate = $AdmissionDate;
	}

	public function setWardId( $WardId ){
		$this->m_intWardId = $WardId;
	}

	public function setBeedNumber( $BeedNumber ){
		$this->m_intBeedNumber = $BeedNumber;
	}

	public function setCasePaperCount( $CasePaperCount ){
		$this->m_intCasePaperCount = $CasePaperCount;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into PATIENT_DETAILS (patient_id, monthly_income, relieved_date, discharge_date, admission_date, ward_id, beed_number, case_paper_count, created_by, created_on, updated_by, updated_on) values (" . $this->getPatientId() . ", " . $this->getMonthlyIncome() . ", '" . $this->getRelievedDate() . "', '" . $this->getDischargeDate() . "', '" . $this->getAdmissionDate() . "', " . $this->getWardId() . ", " . $this->getBeedNumber() . ", " . $this->getCasePaperCount() . ", " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE PATIENT_DETAILS set  patient_id= " . $this->getPatientId() . ", monthly_income= " . $this->getMonthlyIncome() . ", relieved_date= '" . $this->getRelievedDate() . "', discharge_date= '" . $this->getDischargeDate() . "', admission_date= '" . $this->getAdmissionDate() . "', ward_id= " . $this->getWardId() . ", beed_number= " . $this->getBeedNumber() . ", case_paper_count= " . $this->getCasePaperCount() . ", created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM patient_details WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'patient_details'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}